﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using NUnit.Framework;

using Spring.Context;
using Spring.Context.Support;
using Spring.Util;
using Spring.Data.NHibernate.Support;

using efish.Framework.Dao;
using efish.Framework.Model;

namespace efish.IntegrationTest.Dao
{
    [TestFixture]
    public class TestCategoriesDAO
    {
        private IApplicationContext ctx;
        private CategoriesDAO dao;

        [SetUp]
        public void SetUp()
        {
            ctx = ContextRegistry.GetContext();
            dao = ctx["CategoriesDAO"] as CategoriesDAO;
        }

        [Test]
        public void TestGetTopCategories()
        {
            using (new SessionScope())
            {
                IList<Category> items = dao.GetTopCategories();

                //assertions....
                Console.WriteLine("INFO\tThe count of top items is {0}", items.Count);

                foreach (Category item in items)
                {
                    PrintInfo(item);
                }
            }
        }

        public void PrintInfo(Category category)
        {
            Console.WriteLine("INFO\t{0}\t{1}\t{2}", category.ID, category.Title, category.ChildCategories.Count);

            foreach (Category item in category.ChildCategories)
            {
                PrintInfo(item);
            }
        }
    }
}

